/**
 * 
 */
package cn.jhz.filesharingsystem.util;

import java.lang.reflect.Method;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author asus
 *
 */
public class AuthUtil {
	
	private AuthUtil() {
		
	}
	@SuppressWarnings("rawtypes")
	static private final Class[] methods = {RequestMapping.class,DeleteMapping.class,GetMapping.class,PostMapping.class,PutMapping.class}; 
	
	@SuppressWarnings("unchecked")
	static public String getURL(Method method) {
		Object mapping;
		for(int i=0; i<AuthUtil.methods.length; i++) {
			if((mapping = method.getAnnotation(AuthUtil.methods[i]))!=null) {					
				return AuthUtil.judgeMethod(mapping,i);
			}
		}
		return null;
	}
	
	static private String judgeMethod(Object obj,int i) {
		switch (i) {
		case 0:
			return ((RequestMapping)obj).value()[0];
		case 1:
			return ((DeleteMapping)obj).value()[0];
		case 2:
			return ((GetMapping)obj).value()[0];
		case 3:
			return ((PostMapping)obj).value()[0];
		case 4:
			return ((PutMapping)obj).value()[0];
		default:
			return null; 
		}
	}
}
